<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('疫情防控部门树选择')" />
	<th:block th:include="include :: ztree-css" />
</head>
<style>
	body{height:auto;font-family: "Microsoft YaHei";}
	button{font-family: "SimSun","Helvetica Neue",Helvetica,Arial;}
</style>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
	<form class="form-horizontal m" id="form-user-edit">
		<div class="form-group" id="authDataScope" >
			<label class="col-sm-3 control-label">部门设置：</label>
			<div class="col-sm-8">
				<label class="check-box">
					<input type="checkbox" value="1" checked>展开/折叠</label>
				<label class="check-box">
					<input type="checkbox" value="2">全选/全不选</label>
				<!--<label class="check-box">
					<input type="checkbox" value="3">父子联动</label>-->
				<div id="deptTrees" class="ztree ztree-border"></div>
			</div>
		</div>
	</form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: ztree-js" />
<script type="text/javascript">
	$(function() {
		var daptIds = $("#deptIds").val();
		var url = ctx + "original/dept/treeData";
		var options = {
			id: "deptTrees",
			url: url,
			check: { enable: true, nocheckInherit: true, chkboxType: { "Y": "", "N": ""  } },
			expandLevel: 2
		};
		$.tree.init(options);
	});

	$('input').on('ifChanged', function(obj){
		var type = $(this).val();
		var checked = obj.currentTarget.checked;
		if (type == 1) {
			if (checked) {
				$._tree.expandAll(true);
			} else {
				$._tree.expandAll(false);
			}
		} else if (type == "2") {
			if (checked) {
				$._tree.checkAllNodes(true);
			} else {
				$._tree.checkAllNodes(false);
			}
		} else if (type == "3") {
			if (checked) {
				$._tree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
			} else {
				$._tree.setting.check.chkboxType = { "Y": "", "N": "" };
			}
		}
	})

	function submitHandler() {
		if ($.validate.form()) {
			edit();
		}
	}

	function edit() {
		var deptIds = $.tree.getCheckedNodes();
		var deptNames = $.tree.getCheckedNodes("name");

		if (deptIds.length == 0) {
			$.modal.alertWarning("请至少选择一个部门");
			return;
		}
		activeWindow().selectDeptCall(deptIds,deptNames);
		$.modal.close();
	}

</script>
</body>
</html>
